import { request } from '@/utils/request'
import type {
  Restaurant,
  CreateRestaurantDto,
  UpdateRestaurantDto,
  PaginatedRestaurants,
  RestaurantFilters,
  PaginationParams,
  ApiResponse
} from './types'

/**
 * 餐厅管理API
 */
export const restaurantApi = {
  /**
   * 获取餐厅列表（分页）
   * @param filters 筛选条件
   * @param pagination 分页参数
   */
  getRestaurants(
    filters?: RestaurantFilters,
    pagination?: PaginationParams
  ) {
    const params = {
      ...filters,
      ...pagination
    }
    return request.get<PaginatedRestaurants>('/restaurants', params)
  },

  /**
   * 获取所有餐厅（不分页）
   * @param filters 筛选条件
   */
  getAllRestaurants(filters?: RestaurantFilters) {
    return request.get<Restaurant[]>('/restaurants/all', filters)
  },

  /**
   * 根据ID获取餐厅详情
   * @param id 餐厅ID
   */
  getRestaurantById(id: string) {
    return request.get<Restaurant>(`/restaurants/${id}`)
  },

  /**
   * 创建餐厅
   * @param data 餐厅数据
   */
  createRestaurant(data: CreateRestaurantDto) {
    return request.post<Restaurant>('/restaurants', data)
  },

  /**
   * 更新餐厅
   * @param id 餐厅ID
   * @param data 更新数据
   */
  updateRestaurant(id: string, data: UpdateRestaurantDto) {
    return request.put<Restaurant>(`/restaurants/${id}`, data)
  },

  /**
   * 删除餐厅
   * @param id 餐厅ID
   */
  deleteRestaurant(id: string) {
    return request.delete<void>(`/restaurants/${id}`)
  },

  /**
   * 批量删除餐厅
   * @param ids 餐厅ID数组
   */
  batchDeleteRestaurants(ids: string[]) {
    return request.delete<void>('/restaurants/batch', { ids })
  },

  /**
   * 获取餐厅分类列表
   */
  getCategories() {
    return request.get<string[]>('/restaurants/categories')
  },

  /**
   * 获取频率规则列表
   */
  getFrequencyRules() {
    return request.get<string[]>('/restaurants/frequency-rules')
  },

  /**
   * 搜索餐厅
   * @param keyword 搜索关键词
   */
  searchRestaurants(keyword: string) {
    return request.get<Restaurant[]>('/restaurants/search', { keyword })
  }
}

export default restaurantApi